package com.gdust.hzx.manager.controller;

import com.gdust.hzx.manager.service.SysMenuService;
import com.gdust.spzx.common.log.annotation.Log;
import com.gdust.spzx.common.log.enums.OperatorType;
import com.gdust.hzx.model.entity.system.SysMenu;
import com.gdust.hzx.model.vo.common.Result;
import com.gdust.hzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: SysMenuController
 * Package: com.gdust.spzx.manager.controller
 * Description:
 *
 * @Author syun
 * @Create 2024/11/24 15:44
 * @Version 1.0
 */
@RestController// @RestController: 专用于restful风格的注解 = @Controller (控制器) + @ResponseBody (方法返回值为json)
@RequestMapping(value="/admin/system/sysMenu")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    /**
     * 查询菜单
     * @return 响应结果实体类返回结果与业务状态码
     */
    @GetMapping("/findNodes")
    public Result findNodes(){
        //自定义方法：查询菜单
        List<SysMenu> list = sysMenuService.findNodes();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    /**
     * 添加菜单
     * @param sysMenu 系统菜单实体类
     * @return 响应结果实体类返回结果与业务状态码
     */
    @Log(title = "添加菜单",businessType = 1,operatorType = OperatorType.MANAGE)
    @PostMapping("/save")
    public Result save(@RequestBody SysMenu sysMenu){
        //自定义方法：添加菜单
        sysMenuService.save(sysMenu);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改菜单
     * @param sysMenu 系统菜单实体类
     * @return 响应结果实体类返回结果与业务状态码
     */
    @Log(title = "修改菜单",businessType = 2,operatorType = OperatorType.MANAGE)
    @PutMapping("/update")
    public Result update(@RequestBody SysMenu sysMenu){
        //自定义方法：修改菜单
        sysMenuService.update(sysMenu);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 删除菜单
     * @param id id 菜单的唯一标识（路径参数）
     * @return 响应结果实体类返回结果与业务状态码
     */
    @Log(title = "删除菜单",businessType = 3,operatorType = OperatorType.MANAGE)
    @DeleteMapping("removeById/{id}")
    public Result removeById(@PathVariable("id") Long id){
        //自定义方法删除菜单
        sysMenuService.removeById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }




}
